-
Notifications
You must be signed in to change notification settings - Fork 83
Allow CSS custom properties to be used without converting to camel case #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow CSS custom properties to be used without converting to camel case #85
Conversation
Is there a reason to handle this in this library? I’m doing the same thing in cssta, but handle the splitting filter variable declarations before handing them off to here (see Happy to hear if there’s a reason to do otherwise though! |
What I thought was that it's easy to handle here because the values for the custom props will be handled by the parser, e.g. --my-prop: 56px; to "--my-prop": 56 |
I could of course handle them in the library level, but then that's just unnecessary boilerplate to: first strip out the |
I’m not sure that works. If you did,
This shouldn’t work, but I think in your example it will |
@jacobp100 I'm not sure what your point is here. I think that I need to explain what I'm trying to achive. :) What did previously was to allow various CSS units to be passed through the parser: With that I was able to add support for CSS viewport units, which are calculated at runtime. What I want now is to pass custom properties (e.g. The part where the custom property gets used (e.g. So For example I want --my-prop: 4px;
--other-prop: 4vw;
font-size: var(--other-prop); to this: {
"--my-prop": 4,
"--other-prop": "4vw",
fontSize: "var(--other-prop)"
} That code will just give a warning or throw an error in React Native, but if I have a library between the result from this parser and React Native, the end result can look like this: {
fontSize: 15
} |
I definitely get what you're trying to do! Maybe a better example of what I'm trying to say could be,
If you removed the px in This won't just apply to |
You are correct that any shorthand values would throw if you use them together with As a workaround I can match the shorthand values in a similar way that --body-size: 14px;
font: var(--body-size) "Helvetica"; ↓ ↓ ↓ ↓ ↓ ↓ --body-size: 14px;
font: 53463023px "Helvetica"; and then just replace ↓ ↓ ↓ ↓ ↓ ↓ {
"--body-size": 14
"fontFamily": "Helvetica",
"fontSize": 53463023,
"fontStyle": "normal",
"fontVariant": [],
"fontWeight": "normal"
} ↓ ↓ ↓ ↓ ↓ ↓ {
"--body-size": 14
"fontFamily": "Helvetica",
"fontSize": "var(--body-size)",
"fontStyle": "normal",
"fontVariant": [],
"fontWeight": "normal"
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go for it 👍
@jacobp100 Now that I'm thinking about this again, maybe it would be better to allow the short hand props to pass both CSS functions and length units through the parser. I can use the workaround I mentioned, but if I would implement support for any other CSS function (e.g. calc), then my code would be full of boilerplate code to handle the workarounds. So what if we whitelist the most common CSS functions and make the parser transform this: --body-size: 14px;
font: var(--body-size) "Helvetica"; into this: {
"--body-size": 14
"fontFamily": "Helvetica",
"fontSize": "var(--body-size)",
"fontStyle": "normal",
"fontVariant": [],
"fontWeight": "normal"
} What do you think? |
That won't quite work, since CSS
The expected value for this would be |
Oh I didn't think of that! I guess in that case the only way is to implement the logic in my library |
Might be best! The logic gets quite complicated, especially when variables reference other variables! |
Currently the parser turns any CSS property names to camel case.
There is however a use case for implementing support for CSS Custom properties. Here's an example of how custom props can be used:
kristerkari/react-native-stylus-transformer#3 (comment)
So if we just don't turn the custom property to camel case, everything works like it did before, but implementations of updating custom properties with Javascript are now possible.
ping @jacobp100